package cn.broadsense.thrid.api;


import cn.broadsense.thrid.result.AlgorithmResult;
import cn.broadsense.thrid.constant.DaHuaApiUrlConstant;
import cn.broadsense.thrid.param.*;
import cn.broadsense.thrid.result.*;
import cn.broadsense.thrid.utils.DaHuaHttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 大华算法相关接口
 *
 * @author pengxin
 * @date 2022-10-08 11:16
 */
@Slf4j
@Component
public class AlgorithmRepository extends BaseRepository {


    /**
     * 算法能力查询接口
     *
     * @param param
     * @return
     */
    public AlgorithmResult algorithms(AlgorithmListParam param) {
        String token = getCToken();
        param.setUrl(cUrl + DaHuaApiUrlConstant.Algorithm.ALGORITHMS);
        AlgorithmResult result = DaHuaHttpUtils.postRest(token, param);
        return result;
    }


    /**
     * 更改算法能力状态
     *
     * @param param
     * @return
     */
    public String changeAlgorithmStatus(AlgorithmStatusParam param) {
        String token = getCToken();
        param.setUrl(cUrl + DaHuaApiUrlConstant.Algorithm.ALGORITHMS_STATUS);
        return DaHuaHttpUtils.putRest(token, param);
    }


    /**
     * 算法查询接口
     *
     * @param param
     * @return
     */
    public AlgorithmEventResult algorithmsEvents(AlgorithmEventsParam param) {
        String token = getCToken();
        param.setUrl(cUrl + DaHuaApiUrlConstant.Algorithm.ALGORITHMS_EVENTS);
        return DaHuaHttpUtils.postRest(token, param);
    }

    /**
     * 场景列表
     *
     * @param param
     * @return
     */
    public AlIndustryScenesResult industryScenes(AlIndustryScenesParam param) {
        String token = getCToken();
        param.setUrl(cUrl + DaHuaApiUrlConstant.Algorithm.ALGORITHMS_INDUSTRYSCENES);
        return DaHuaHttpUtils.getRest(token, param);
    }

    /**
     * 告警规则
     *
     * @return
     */
    public AlAlarmRulesResult alarmRules() {
        BaseParam baseParam = new BasePageParam() {
            @Override
            public void checkParam() {

            }

            @Override
            public Class getResultClass() {
                return AlAlarmRulesResult.class;
            }
        };
        String token = getCToken();
        baseParam.setUrl(cUrl + DaHuaApiUrlConstant.Algorithm.ALARM_RULES);
        return DaHuaHttpUtils.getRest(token, baseParam);
    }

    /**
     * @param algorithmId
     * @return
     */
    public String readFile(String algorithmId) {
        BaseParam baseParam = new BasePageParam() {
            @Override
            public void checkParam() {

            }

            @Override
            public Class getResultClass() {
                return String.class;
            }
        };
        String token = getCToken();
        baseParam.setUrl(cUrl + DaHuaApiUrlConstant.Algorithm.ALGORITHMS_READFILE);
        return DaHuaHttpUtils.getRest(token, baseParam);
    }

    /**
     * 算法版本
     *
     * @param param
     * @return
     */
    public List<AlVersionResult> algorithmsVersion(AlVersionParam param) {
        String token = getCToken();
        param.setUrl(cUrl + DaHuaApiUrlConstant.Algorithm.ALGORITHMS_VERSION);
        return DaHuaHttpUtils.getRest(token, param);
    }

    /**
     * 算法间隔时间
     *
     * @param param
     * @return
     */

    public String algorithmsDuration(AlDurationParam param) {
        String token = getCToken();
        param.setUrl(cUrl + DaHuaApiUrlConstant.Algorithm.ALGORITHMS_DURATION);
        return DaHuaHttpUtils.getRest(token, param);
    }


}
